from google.appengine.ext import db

from google.appengine.ext.db import djangoforms
from google.appengine.ext.db import polymodel

from models.Groups import *
from models.Topics import *
from models.Messages import *
from models.Authentication import *

import logging

class Audit(polymodel.PolyModel):
    action = db.StringProperty(required=True)
    objectID = db.IntegerProperty(required=False)
    userID = db.IntegerProperty(required=True)
    date = db.DateTimeProperty(required=True)
    ip = db.StringProperty(required=True)

    
    # Set by the methods below
    objectName = db.StringProperty(required=False)

    def setGroup(self):
        group = Group.get_by_id(int(self.objectID))
        self.objectName = group.title
    def setTopic(self):
        topic = Topic.get_by_id(int(self.objectID))
        self.objectName = topic.topic
    def setMessage(self):
        message = Message.get_by_id(int(self.objectID))
        self.objectName = message.subject

    def getUserName(self):
        user = User.get_by_id(self.userID)
        return user.displayname
